﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using LabMS.BLL;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ExtendBLL
{
    public class Responsibility
    {
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ExtendModule.ResponsibilityAndOther GetModel(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select r.id, r.Resp_Name, r.Resp_Content, r.Resp_Lab,r.Intro,r.Summary, l.ID as Lab_ID,l.Lab_Name from responsibility r left join lab l on r.Resp_Lab=l.[id] ");
            strSql.Append(" where r.ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            ExtendModule.ResponsibilityAndOther model = new ExtendModule.ResponsibilityAndOther();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Resp_Lab"].ToString() != "")
                {
                    model.Resp_Lab = int.Parse(ds.Tables[0].Rows[0]["Resp_Lab"].ToString());
                }
                model.Resp_Name = ds.Tables[0].Rows[0]["Resp_Name"].ToString();
                model.Resp_Content = ds.Tables[0].Rows[0]["Resp_Content"].ToString();
                model.Intro = ds.Tables[0].Rows[0]["Intro"].ToString();
                model.Summary = ds.Tables[0].Rows[0]["Summary"].ToString();
                if (ds.Tables[0].Rows[0]["Lab_ID"].ToString() != "")
                {
                    model.Lab_ID = int.Parse(ds.Tables[0].Rows[0]["Lab_ID"].ToString());
                }
                model.Lab_Name = ds.Tables[0].Rows[0]["Lab_Name"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        public List<ExtendModule.ResponsibilityAndOther> GetResponsList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select r.id, r.Resp_Name, r.Resp_Content, r.Resp_Lab,r.Intro,r.Summary, l.ID as Lab_ID,l.Lab_Name from responsibility r left join lab l on r.Resp_Lab=l.[id] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }

            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            List<ExtendModule.ResponsibilityAndOther> modelList = new List<ExtendModule.ResponsibilityAndOther>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                ExtendModule.ResponsibilityAndOther model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ExtendModule.ResponsibilityAndOther();
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["Resp_Lab"].ToString() != "")
                    {
                        model.Resp_Lab = int.Parse(ds.Tables[0].Rows[n]["Resp_Lab"].ToString());
                    }
                    model.Resp_Name = ds.Tables[0].Rows[n]["Resp_Name"].ToString();
                    model.Resp_Content = ds.Tables[0].Rows[n]["Resp_Content"].ToString();
                    model.Intro = ds.Tables[0].Rows[n]["Intro"].ToString();
                    model.Summary = ds.Tables[0].Rows[n]["Summary"].ToString();
                    if (ds.Tables[0].Rows[n]["Lab_ID"].ToString() != "")
                    {
                        model.Lab_ID = int.Parse(ds.Tables[0].Rows[n]["Lab_ID"].ToString());
                    }
                    model.Lab_Name = ds.Tables[0].Rows[n]["Lab_Name"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}
